package oktx.sample.dubbo;

import com.alibaba.dubbo.config.annotation.Reference;
import oktx.sample.dubbo.model.Book;
import oktx.sample.dubbo.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by dave on 18-5-20 上午11:20.
 */
@Service
@com.alibaba.dubbo.config.annotation.Service
public class BookApiImpl implements BookApi {
    @Autowired BookMapper bookMapper;
    @Reference(check = false) UserApi userApi;

    @Override
    public Book addBook(Book book) {
        bookMapper.insert(book);
        User u = new User();
        u.setName("小二");
        u.setPhone("13211112222");
        userApi.addUser(u);
        return book;
    }

    @Override
    public List<Book> getBooks() {
        return bookMapper.getList();
    }

    @Override
    public void removeAllBooks() {
        bookMapper.clear();
    }
}
